package cn.wen.xframe.security;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;

import cn.wen.javax.security.IUser;
import cn.wen.bases.framework.struts.action.BaseAction;
import cn.wen.bases.framework.struts.action.model.BaseModel;
import cn.wen.bases.service.security.UserService;

/**
 * Title：用户相关Action
 * <p>
 * Description：包含：用户登录，更新用户，查询用户等。
 * <p>
 * Copyright：Copyright (c) 2010-2012
 * 
 * @author <a href="mailto:ct_wen@qq.com">ctwen</a>, 温承瑭
 * @version Revision：1.0 Date：2012/4/22 Description：初完成。
 *          <p>
 */
public class UserAction extends BaseAction implements ServletRequestAware {

    private Logger log = Logger.getLogger(getClass());

    private BaseModel model = new BaseModel();

    @Override
    public Object getModel() {
	return model;
    }

    public String doLogin() throws Exception {
	IUser user = userService.login(request);
	model.setFeedback(userService.getMessage());
	if (null == user) return LOGIN_FAILRE;
	return super.execute();
    }

    private UserService userService;

    public void setUserService(UserService userService) {
	this.userService = userService;
    }

    private HttpServletRequest request;

    @Override
    public void setServletRequest(HttpServletRequest request) {
	this.request = request;
    }

}
